package com.bjsxt.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.UserAddress;
import com.bjsxt.model.Result;
import com.bjsxt.service.UserAddressService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;

/**
 * description:
 * 用户钱包地址控制层
 * TODO: 这里的访问权限控制在书写的时候对应的权限表没有对应的权限, 需要后期加入, 权限访问还是要加的, 暂时注释掉
 * TODO: 这里的币种名称在财务系统中，财务系统没有进行开发，后期会进行添加。
 *
 * @author ALIENWARE <br />
 * @date 2021/8/24
 */
@RestController
@RequestMapping("/userAddress")
@Api(tags = "用户钱包地址控制器")
public class UserAddressController {

    /**
     * 用户钱包地址业务层接口
     */
    @Autowired
    private UserAddressService userAddressService;

    /**
     * 分页查询用户的钱包地址
     *
     * @param page   分页对象<UserAddress>
     * @param userId 用户 id
     * @return 统一响应对象
     */
    @GetMapping
    //@PreAuthorize("hasAuthority('user_bank_query')")
    @ApiOperation(value = "分页查询用户的钱包地址", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "userId", value = "用户 Id", dataType = "Long", required = true, paramType = "query", example = "1")
    })
    public Result<Page<UserAddress>> findByPage(@ApiIgnore Page<UserAddress> page, @NotNull Long userId) {
        // 查询时间, 我们讲最近新增的, 修改的数据优先展示, 排序 last_update_time
        page.addOrder(OrderItem.desc(UserAddress.COL_LAST_UPDATE_TIME));
        // 调用业务层进行分页数据的查询
        Page<UserAddress> userAddressPage = userAddressService.pageByUserId(page, userId);
        // 返回响应数据
        return Result.success(userAddressPage);
    }
}
